import json

from ronglian_sms_sdk import SmsSDK

accId = '8a216da878005a800178d30a4ed04f10'
accToken = '8cae05731fe9416da36e6090344732ac'
appId = '8a216da878005a800178d30a4fcb4f16'


class SmsUtil:
    def __new__(cls, *args, **kwargs):
        if not hasattr(SmsUtil, '_instance'):
            cls._instance = super().__new__(cls, *args, **kwargs)
            cls._instance.sms_sdk = SmsSDK(accId, accToken, appId)
        return cls._instance

    def send_message(self, tid, mobile, datas):
        # sdk = SmsSDK(accId, accToken, appId)
        # tid = '1'
        # mobile = '19852740137'
        # datas = ('985634', '2')
        resp = self.sms_sdk.sendMessage(tid, mobile, datas)
        resp_dict = json.loads(resp)
        if resp_dict.get('statusCode') == '000000':
            print("发送短信成功")
            return 0

        else:
            print('发送短信失败')
            return 1


if __name__ == '__main__':
    SmsUtil().send_message('1', '19852740137', ('456853', '2'))